//index.js
var Bmob = require('../../utils/bmob.js');
//获取应用实例
const app = getApp()
var list=require('../../Data/data.js')
//console.log(list)
Page({
  data: {
    searchVal:'',
    foodList: [
      {
        "id": 0,
        "src": "http://1img.mgtv.com/preview/sp_images/2017/shenghuo/291200/3768921/20170105162653378.jpg",
        "desc": "旺财蛋糕费南雪"
      },
      {
        "id": 1,
        "src": "http://0img.mgtv.com/preview/sp_images/2017/shenghuo/291200/3768925/20170105162125385.jpg",
        "desc": "鸡金银汤上汤西兰花"
      },
      {
        "id": 2,
        "src": "http://0img.mgtv.com/preview/sp_images/2017/shenghuo/291200/3768928/20170105161725813.jpg",
        "desc": "嚤嚤喳喳"
      },
      {
        "id": 3,
        "src": "http://2img.mgtv.com/preview/sp_images/2017/shenghuo/291200/3768932/20170105161110380.jpg",
        "desc": "咸蛋黄焗南瓜"
      },
      {
        "id": 4,
        "src": "http://0img.mgtv.com/preview/sp_images/2017/shenghuo/309467/4013191/20170714153518445.jpg",
        "desc": "蒸制和盐烤蛏子"
      }
    ],
    foodyami: [
      {
        "id": 0,
        "src": "http://images.meishij.net/p/20120413/7188c8c9bfe17b829a08e9a4b5fd7737.jpg",
        "desc": "虎皮青椒",
        "title":"街坊美食",
        "src2":"http://2img.mgtv.com/preview/sp_images/2017/shenghuo/291200/3768932/20170105161110380.jpg"
      },
      {
        "id": 1,
        "src": "https://s1.st.meishij.net/rs/199/170/3917699/n3917699_142906235435395.jpg",
        "desc": "麻辣鸡块",
        "title": "香辣小吃",
        "src2": "http://2img.mgtv.com/preview/sp_images/2017/shenghuo/309467/3896104/20170411153342124.jpg"
      },
      {
        "id": 2,
        "src": "https://s1.st.meishij.net/rs/00/00//n_154518135646133.jpg",
        "desc": "酸汤肥牛",
        "title": "绝顶美食",
        "src2": "http://0img.mgtv.com/preview/sp_images/2017/shenghuo/309467/3990142/20170629153952135.jpg"
      },
      {
        "id": 3,
        "src": "http://images.meishij.net/p/20110218/5985ce73250273ea1c8cb38cacb10c8d.jpg",
        "desc": "酱猪蹄",
        "title": "大猪蹄子",
        "src2": "http://3img.mgtv.com/preview/sp_images/2017/shenghuo/309467/4013190/20170714151445401.jpg"
      },
      {
        "id": 4,
        "src": "http://images.meishij.net/p/20130911/43d298de24cd3daf53a58d883ce2a205.jpg",
        "desc": "干煸四季豆",
        "title": "美味小炒",
        "src2": "http://1img.mgtv.com/preview/sp_images/2017/shenghuo/309467/4013194/20170714152514715.jpg"
      },
      {
        "id": 5,
        "src": "http://images.meishij.net/p/20130301/aedbffbbfb326d3943eaa630a5972fc5.jpg",
        "desc": "魔芋烧鸭",
        "title": "天上人鸭",
        "src2": "http://0img.mgtv.com/preview/sp_images/2017/shenghuo/309467/4013195/20170714154245327.jpg"
      }]
  },
  onLoad: function () {
    // 查看是否授权
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称
          wx.getUserInfo({
            success: function (res) {
              console.log(res.userInfo)
            }
          })
        }
      }
    })
        var _this = this;
        var index = Bmob.Object.extend("first-picture");
        var query = new Bmob.Query(index);
        //添加数据，第一个入口参数是null
        // 查询所有数据
        query.find({
          success: function (results) {

            console.log("共查询到 " + results.length + " 条记录");
            // 循环处理查询到的数据
            for (var i = 0; i < results.length; i++) {
              var object = results[i];
              console.log(object.id + ' - ' + object.get('src'));
            }
            _this.setData({
              picture: results
            });
          },
          error: function (error) {
            console.log("查询失败: " + error.code + " " + error.message);
          }
        });
      
    var content = Bmob.Object.extend("first-content");
    var query2 = new Bmob.Query(content);
    //添加数据，第一个入口参数是null
    // 查询所有数据
    query2.find({
      success: function (results) {

        console.log("共查询到 " + results.length + " 条记录");
        // 循环处理查询到的数据
        for (var i = 0; i < results.length; i++) {
          var object = results[i];
          console.log(object.id + ' - ' + object.get('src'));
        }
        _this.setData({
          content: results
        });
      },
      error: function (error) {
        console.log("查询失败: " + error.code + " " + error.message);
      }
    });
  },
  //事件处理函数
  bindViewTap: function (e) {
    console.log(e.currentTarget)
    var id = e.currentTarget.id
    if (id == 'OC7UBBBX') {
      wx.navigateTo({
        url: '../dishes/cake/cake'
      })
    }
    if (id == 'OqcbCCCJ') {
      wx.navigateTo({
        url: '../dishes/soup/soup'
      })
    }
    if (id == 'eIYT000W') {
      wx.navigateTo({
        url: '../detail/detail'
      })
    }

  },
  bindFoodTap: function(e){
    wx.navigateTo({
      url: 'street food/street food'
    })
  },
  bindGetUserInfo(e) {
    console.log(e.detail.userInfo)
  },

  /*获取input中的数据*/
  wxSearchInput: function(e){
    this.setData({
      searchVal:e.detail.value
    })
    //console.log(this.data.searchVal)
  },

  searchBtn: function () {
    var val = this.data.searchVal
    
    if( (/\s/).test(val) ){
      console.log('em')
    }else{
    //console.log(val)
      if(val=='费南雪')
      {
        wx.navigateTo({
          url: '/pages/dishes/cake/cake',
        })
      }else if(val=='西兰花'){
        wx.navigateTo({
          url: '/pages/dishes/soup/soup',
        })
        } else if (val == '香菇青菜') {
          wx.navigateTo({
            url: '/pages/dishes/vegetables/vegetables',
          })
        }else{
          wx.showToast({
            title: '抱歉亲，没找到！',
            icon: 'none'
          })
          //console.log('no')
        }
      }
  }
 
  
})

